package org.me.nyx.server;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class Movies
 */
@WebServlet("/Movies")
public class Movies extends HttpServlet {
	private static final long serialVersionUID = 1L;

	private static String createMovieString(String name, String description) {
		StringBuilder sb = new StringBuilder();
		sb.append("movie { \"name\": \"").append(name).append("\", \"description\": \"")
			.append(description).append("\"}\n");
		
		return sb.toString();
	}
	
	private static String getMovieString() {
		String movie1 = "Pitch Black";
		String desc1 = "When their ship crashe-lands on a remote planet, the marooned passengers soon lear that " +
				"escaped convict Riddick isn't the only thing they have to fear. Deadly creatures lurk in the " +
				"shadows waiting to attack in the dark and the planet is rapidly plunging into the utter blackness " +
				"of a total eclipse. With the body count rising the doomed survivors are forced to turn to Riddick " +
				"with his eerie eyes to guide them through the darkness to safty. With time running out there's " +
				"only one rule: Stay in the light.";
		
		String movie2 = "Bourne Identity";
		String desc2 = "Found with two bullets in his back, Jason Bourne discovers he has the skills of a very dangerous " +
				"man and no memory of his violent past. Racing to unlock the secret of his own identity, he discovers the " +
				"deadly truth: he's an elite government agent, a 30 million dollar weapon the government no longer trusts. " +
				"Now this top operative is the government's number one target in this super-charged, thrill-a-minute spactacular " +
				"loaded with \"Non-stop action\"";
		
		return createMovieString(movie1, desc1) + createMovieString(movie2, desc2);
	}
	
    /**
     * Default constructor. 
     */
    public Movies() {
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.write(getMovieString());
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.write(getMovieString());
	}

}
